package br.ufrpe.bsi.pvs.view.admin;

import java.awt.Color;
import java.awt.List;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.JLabel;

import org.jdom2.Document;

import br.ufrpe.bsi.pvs.Fachada;
import br.ufrpe.bsi.pvs.control.BSFactory;
import br.ufrpe.bsi.pvs.control.roupa.RoupaBs;
import br.ufrpe.bsi.pvs.model.funcionario.Funcionario;
import br.ufrpe.bsi.pvs.model.roupa.Roupa;
import br.ufrpe.bsi.pvs.view.PvsFrame;
import br.ufrpe.bsi.pvs.xml.transformer.FuncionarioXML;
import br.ufrpe.bsi.pvs.xml.transformer.RoupaXML;

/**
 *
 * @author sergio
 */
public class TelaMenuPrincipal extends javax.swing.JPanel {

    public static TelaMenuPrincipal INSTANCE = new TelaMenuPrincipal();

    private TelaMenuPrincipal() {
        initComponents();

        lbcadastroroupas.addMouseListener(new MouseHandler());
        lbcadastrofuncionario.addMouseListener(new MouseHandler());
        lbpesquisafuncionario.addMouseListener(new MouseHandler());
        lbpesquisarroupas.addMouseListener(new MouseHandler());
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        lbcadastroroupas = new javax.swing.JLabel();
        lbpesquisarroupas = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lbcadastrofuncionario = new javax.swing.JLabel();
        lbpesquisafuncionario = new javax.swing.JLabel();

        setBackground(java.awt.Color.white);

        jLabel1.setBackground(new java.awt.Color(254, 254, 254));
        jLabel1.setFont(new java.awt.Font("Gabriola", 0, 36)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 0));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Roupas");
        jLabel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(205, 205, 205)));
        jLabel1.setOpaque(true);

        lbcadastroroupas.setBackground(java.awt.Color.black);
        lbcadastroroupas.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        lbcadastroroupas.setForeground(new java.awt.Color(255, 255, 255));
        lbcadastroroupas.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbcadastroroupas.setText("Cadastrar");
        lbcadastroroupas.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        lbcadastroroupas.setMaximumSize(new java.awt.Dimension(175, 35));
        lbcadastroroupas.setMinimumSize(new java.awt.Dimension(175, 35));
        lbcadastroroupas.setOpaque(true);
        lbcadastroroupas.setPreferredSize(new java.awt.Dimension(175, 35));
        lbcadastroroupas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbcadastroroupasMouseClicked(evt);
            }
        });

        lbpesquisarroupas.setBackground(java.awt.Color.black);
        lbpesquisarroupas.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        lbpesquisarroupas.setForeground(new java.awt.Color(255, 255, 255));
        lbpesquisarroupas.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbpesquisarroupas.setText("Pesquisar");
        lbpesquisarroupas.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        lbpesquisarroupas.setMaximumSize(new java.awt.Dimension(175, 35));
        lbpesquisarroupas.setMinimumSize(new java.awt.Dimension(175, 35));
        lbpesquisarroupas.setOpaque(true);
        lbpesquisarroupas.setPreferredSize(new java.awt.Dimension(175, 35));
        lbpesquisarroupas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbpesquisarroupasMouseClicked(evt);
            }
        });

        jLabel7.setBackground(new java.awt.Color(254, 254, 254));
        jLabel7.setFont(new java.awt.Font("Gabriola", 0, 36)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(0, 0, 0));
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Funcionarios");
        jLabel7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(205, 205, 205)));
        jLabel7.setOpaque(true);

        lbcadastrofuncionario.setBackground(java.awt.Color.black);
        lbcadastrofuncionario.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        lbcadastrofuncionario.setForeground(new java.awt.Color(255, 255, 255));
        lbcadastrofuncionario.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbcadastrofuncionario.setText("Cadastrar");
        lbcadastrofuncionario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        lbcadastrofuncionario.setMaximumSize(new java.awt.Dimension(175, 35));
        lbcadastrofuncionario.setMinimumSize(new java.awt.Dimension(175, 35));
        lbcadastrofuncionario.setOpaque(true);
        lbcadastrofuncionario.setPreferredSize(new java.awt.Dimension(175, 35));
        lbcadastrofuncionario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbcadastrofuncionarioMouseClicked(evt);
            }
        });

        lbpesquisafuncionario.setBackground(java.awt.Color.black);
        lbpesquisafuncionario.setFont(new java.awt.Font("Gabriola", 0, 24)); // NOI18N
        lbpesquisafuncionario.setForeground(new java.awt.Color(255, 255, 255));
        lbpesquisafuncionario.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbpesquisafuncionario.setText("Pesquisar");
        lbpesquisafuncionario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        lbpesquisafuncionario.setMaximumSize(new java.awt.Dimension(175, 35));
        lbpesquisafuncionario.setMinimumSize(new java.awt.Dimension(175, 35));
        lbpesquisafuncionario.setOpaque(true);
        lbpesquisafuncionario.setPreferredSize(new java.awt.Dimension(175, 35));
        lbpesquisafuncionario.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lbpesquisafuncionarioMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbcadastroroupas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbpesquisarroupas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbcadastrofuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbpesquisafuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 1001, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lbcadastroroupas, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lbpesquisarroupas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lbcadastrofuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lbpesquisafuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(93, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel1, jLabel7});

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {lbcadastrofuncionario, lbcadastroroupas, lbpesquisafuncionario, lbpesquisarroupas});

    }// </editor-fold>//GEN-END:initComponents

    private void lbpesquisarroupasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbpesquisarroupasMouseClicked
    	PvsFrame.INSTANCE.show(TelaPesquisaRoupa.INSTANCE);
    	RoupaBs bs = BSFactory.getRoupaBs();
		ArrayList<Roupa> result = new ArrayList<Roupa>();
		result = (ArrayList<Roupa>) bs.listar();
    	//Document doc = RoupaXML.parseListRequest();
        //ArrayList<Funcionario> result = (ArrayList<Funcionario>) Fachada.sendRequest(doc);
        TelaPesquisaRoupa.INSTANCE.carregarTabela(result);
        cleanLabel(evt);
    }//GEN-LAST:event_lbpesquisarroupasMouseClicked

    private void lbcadastroroupasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbcadastroroupasMouseClicked
        PvsFrame.INSTANCE.show(TelaCadastroRoupa.INSTANCE);
        cleanLabel(evt);
    }//GEN-LAST:event_lbcadastroroupasMouseClicked

    private void lbcadastrofuncionarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbcadastrofuncionarioMouseClicked
        PvsFrame.INSTANCE.show(TelaCadastroFuncionario.INSTANCE);
        cleanLabel(evt);
    }//GEN-LAST:event_lbcadastrofuncionarioMouseClicked

    private void lbpesquisafuncionarioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbpesquisafuncionarioMouseClicked
        PvsFrame.INSTANCE.show(TelaPesquisarFuncionario.INSTANCE);
        Document doc = FuncionarioXML.parseListRequest();
        ArrayList<Funcionario> result = (ArrayList<Funcionario>) Fachada.sendRequest(doc);
        TelaPesquisarFuncionario.INSTANCE.carregarTabela(result);
    	cleanLabel(evt);
    }//GEN-LAST:event_lbpesquisafuncionarioMouseClicked

    private class MouseHandler extends MouseAdapter {

        @Override
        public void mouseEntered(MouseEvent e) {
            JLabel lb = (JLabel) e.getSource();
            lb.setBackground(Color.WHITE);
            lb.setForeground(Color.BLACK);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            cleanLabel(e);
        }

    }

    private void cleanLabel(MouseEvent e) {
        JLabel lb = (JLabel) e.getSource();
        lb.setBackground(Color.BLACK);
        lb.setForeground(Color.WHITE);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel lbcadastrofuncionario;
    private javax.swing.JLabel lbcadastroroupas;
    private javax.swing.JLabel lbpesquisafuncionario;
    private javax.swing.JLabel lbpesquisarroupas;
    // End of variables declaration//GEN-END:variables
}
